define(['/js/config.js'], () => {
	require(['template','urlSet','header','footer'],(template,urlSet) => {
		class Detail{
			constructor() {
				this.renderDetail().then(() => {
					this.goTo()
					this.page()
				})
			}
			
			renderDetail (begain) {
				var _this = this
				return new Promise (reslove => {
					const id = location.search.slice(4)
					if (begain) {begain = begain}
					else{begain = 0}
					$.get(urlSet.listUrl+id+'?start='+begain,resp => {
						var list1 = resp.data.items.list.filter(list => list.title)
						let list = list1.slice(0,12),
							category = resp.data.category
							this.data = {category,list}
						$('main').html(template('mainTemplate',{...this.data}))
					reslove()
					})
				})
			}
				
			goTo () {
				$('main').on('click','.img img',function () {
					console.log(123)
					const id = $(this).parents('ul').attr('data-id')
					window.open(`/html/detail.html?id=${id}`,'_self')
				})
				$('main').on('click','.title', function () {
					const id = $(this).parents('ul').attr('data-id')
					window.open(`/html/detail.html?id=${id}`,'_self')
				})
			}
			
			page () {
				const _this = this
				$('.page').on('click','span',function () {
					$(this).addClass('point').siblings().removeClass('point')
					const num = Number($(this).index())+1
					const begain = 20 * $(this).index()
					$(this).html('第'+num+'页').siblings().html('')
					_this.renderDetail(begain)
				})
			}
		}
		return new Detail()
	})
})